<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>If/IfEqual/IfNotEqual/IfLess/IfLessOrEqual/IfGreater/IfGreaterOrEqual</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>If/IfEqual/IfNotEqual/IfLess/IfLessOrEqual/IfGreater/IfGreaterOrEqual</h1>

<p>Specifies the command(s) to perform if the comparison of a <a href="../Variables.htm">variable</a> to a value evalutes to TRUE. When more than one command is present, enclose them in a <a href="Block.htm">block</a> (braces).</p>

<pre class="Syntax">IfEqual, var, value (same: if var = value)
IfNotEqual, var, value (same: if var &lt;&gt; value) (!= can be used in place of &lt;&gt;)
IfGreater, var, value (same: if var &gt; value)
IfGreaterOrEqual, var, value (same: if var &gt;= value)
IfLess, var, value (same: if var &lt; value)
IfLessOrEqual, var, value (same: if var &lt;= value)
If var <em>; If var's contents are blank or 0, it is considered false. Otherwise, it is true.</em>

See also: <a href="IfInString.htm">IfInString</a></pre>
<h3>Parameters</h3>
<dl>

  <dt>var</dt>
  <dd><p>The <a href="../Variables.htm">variable</a> name.</p></dd>

  <dt>value</dt>
  <dd><p>A literal string, number, or  variable reference (e.g. %var2%). Value can be omitted if you wish to compare <em>var</em> to an empty string (blank).</p></dd>

</dl>

<h3>Remarks</h3>
<p>If both <em>var</em> and <em>value</em> are purely numeric, they will be compared as numbers rather than as strings. Otherwise, they will be compared alphabetically as strings (that is, alphabetical order will determine whether <em>var</em> is greater, equal, or less than <em>value</em>).</p>
<p>When an IF or an <a href="Else.htm">ELSE</a> owns more than one line, those lines must be enclosed in braces. For example:</p>
<pre>if count &lt;= 0
{
    WinClose Untitled - Notepad
    MsgBox There are no items present.
}</pre>
<p>However, if only one line belongs to the IF or ELSE, the braces are optional.</p>
<p>Another command can only appear on the same line as the IF statement if you use the command-name style. In other words, these are valid:</p>
<pre>IfEqual, x, 1, Sleep, 1
IfGreater, x, 1, EnvAdd, x, 2</pre>
<p>But these are not valid:</p>
<pre>if x = 1 Sleep 1
IfGreater, x, 1, x += 2</pre>
<p>The <a href="IfExpression.htm#otb">One True Brace (OTB) style</a> may <strong>not</strong> be used with these types of if-statements. It can only be used with expression if-statements.</p>
<p>On a related note, the command <a href="IfBetween.htm">if var [not] between LowerBound and UpperBound</a> checks whether a variable is between two values, and <a href="IfIn.htm">if var [not] in value1,value2</a> can be used to check whether a variable's contents exist within a list of values.</p>
<h3>Related</h3>
<p><a href="IfExpression.htm">IF (expression)</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="SetExpression.htm">Assign expression (:=)</a>, <a href="IfIn.htm">if var in/contains MatchList</a>, <a href="IfBetween.htm">if var between</a>, <a href="IfInString.htm">IfInString</a>, <a href="Block.htm">Blocks</a>, <a href="Else.htm">Else</a></p>
<h3>Example</h3>
<pre class="NoIndent">if counter &gt;= 1
    Sleep, 10

if counter &gt;=1   <em>; If an IF has more than one line, enclose those lines in braces:</em>
{
    WinClose, Untitled - Notepad
    Sleep 10
}

if MyVar = %MyVar2%
    MsgBox The contents of MyVar and MyVar2 are identical.
else if MyVar =
{
    MsgBox, 4,, MyVar is empty/blank. Continue?
    IfMsgBox, No
        Return
}
else if MyVar &lt;&gt; ,
    MsgBox The value in MyVar is not a comma.
else
    MsgBox The value in MyVar is a comma.

if Done
    MsgBox The variable Done is neither empty nor zero.</pre>

</body>
</html>
